Skip to content

Conversation

@Gabrielnmds
Copy link

@Gabrielnmds Gabrielnmds commented Dec 17, 2025

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation/refactoring

Description

The zoom fit selected and zoom fit all features allow for the user to change focus between one, some or all exiting nodes, fitting them in the view accordingly. The video below demonstrates both functionalities:

Zoom_fit_test.mp4

Testing

  • Qt version tested:
  • Existing tests still pass
  • Added tests for new functionality (if applicable)

Copy link
Collaborator

@Llcoolsouder Llcoolsouder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous version of contextMenuEvent allows subclasses to completely customize what shows in the context menu. This change would make it so every subclass gets the zoom actions menu (but only if connected to a DataFlowGraphModel).

It might be more in the spirit to the original to keep the new zoom actions as public methods, but leave them disconnected, allowing end users to connect them where they see fit. (We could have a whole collection of inherited default impl actions that could be useful in this way.)

bool isZoomFitMenu;

auto const scenePos = mapToScene(event->pos());
if (auto *dfModel = dynamic_cast<DataFlowGraphModel *>(&nodeScene()->graphModel())) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would caution against coupling the GraphicsView to anything more specific than AbstractGraphModel

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the advice! To solve this, a virtual method was defined in AbstractGraphModel and overridden in DataFlowGraphModel, keeping GraphicsView bound to AbstractGraphModel only.


void GraphicsView::zoomFitAll()
{
fitInView(scene()->itemsBoundingRect(), Qt::KeepAspectRatio);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it's supposed to do the same thing as GraphicsView::centerScene. Do we need both?
I've noticed odd behavior in GraphicsView::centerScene. Is zoomFitAll better? (i.e. should this replace the old impl?)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The central difference between GraphicsView::centerScene and GraphicsView::zoomFitAll is that the former only centralizes the scene without altering the zoom. Since the GraphicsView::centerScene is used to centralize newly loaded scenes I believe both are needed.

QMenu *menu = nullptr;

if (!nodeScene()) return;
bool isZoomFitMenu;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is uninitialized unless all of the immediately following conditions are met.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable is now initialized as false.

Comment on lines 214 to 215

return;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants